
package org.beaconframework.ext.rs.cxf;

import java.net.URI;

import javax.ws.rs.core.MediaType;

import org.apache.cxf.jaxrs.client.WebClient;
import org.beaconframework.ext.rs.WebResource;

public class CXFWebResourceFacade implements WebResource {

    WebClient client;


    public CXFWebResourceFacade(String uri) {
        super();
        this.client = WebClient.create(uri);
    }


    public CXFWebResourceFacade(WebClient client) {
        super();
        this.client = client;
    }


    private WebResource wrap(WebClient client) {
        return new CXFWebResourceFacade(client);
    }


    private WebClient copy() {
        return WebClient.fromClient(client, true);
    }


    public WebResource accept(MediaType... types) {
        return wrap(copy().accept(types));
    }


    public WebResource accept(String... types) {
        return wrap(copy().accept(types));
    }


    public WebResource acceptEncoding(String... encodings) {
        return wrap(copy().acceptEncoding(encodings));
    }


    public WebResource encoding(String encoding) {

        return wrap(copy().encoding(encoding));
    }


    public URI getURI() {
        return client.getCurrentURI();
    }


    /*
     * public Response get() { return client.get(); }
     */

    @Override
    public <T> T get(Class<T> responseClass) {
        // TODO Auto-generated method stub
        return copy().get(responseClass);
    }


    @Override
    public WebResource path(String path) {
        return wrap(copy().path(path));
    }


    @Override
    public WebResource queryParam(String a, String b) {
        return wrap(copy().query(a, b));
    }


    @Override
    public WebResource acceptLanguage(String... languages) {
        // TODO Auto-generated method stub
        return wrap(copy().acceptLanguage(languages));
    }


    @Override
    public WebResource header(String s, Object... vals) {
        return wrap(copy().header(s, vals));

    }

}
